﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COP.Readers;
using COP.Objects.Config;
using System.ComponentModel;
using System.Diagnostics;
using COP.Objects;
using COP.Providers;
using COP.Extractors;
using COP.Objects.Maps;

namespace COP
{
    public class COPProvider
    {
        static IConfigReader staticReader = null;
        static COPProvider()
        {
            staticReader = new XMLConfigReader();
        }

        private IConfigReader reader = null;
        public COPProvider(string sourcePath)
        {
            IConfigProvider provider = new XMLConfigProvider(sourcePath);
            reader = new XMLConfigReader(provider, new XMLExtractor());
        }

        public COPProvider(IConfigReader reader)
        {
            this.reader = reader;
        }

        public bool ExtractBoolean(string tagName)
        {
            return (bool)this.ExtractValue(tagName);
        }

        public object ExtractValue(string tagName)
        {
            return ReadBase(tagName, reader).PullValue();
        }

        /// <summary>
        /// This function provide the map collection consist the value
        /// </summary>
        /// <param name="tagName">Tag which need to be excute</param>
        /// <param name="caller">Refereence of the class which will be called during function call else null</param>
        /// <returns></returns>
        public List<MAPBase> ExtractValueList(string tagName, object caller)
        {
            ConfigBase cBase = ReadBase(tagName, reader);
            cBase.Caller = caller;
            cBase.AppendDelegate();
            return (List<MAPBase>)cBase.PullValue();
        }


        public static bool GetBoolean(string tagName)
        {
            return (bool)GetValue(tagName);
        }

        public static object GetValue(string tagName)
        {
            return ReadBase(tagName,staticReader).PullValue();
        }

        /// <summary>
        /// This function provide the map collection consist the value
        /// </summary>
        /// <param name="tagName">Tag which need to be excute</param>
        /// <param name="caller">Refereence of the class which will be called during function call else null</param>
        /// <returns></returns>
        public static List<MAPBase> GetValueList(string tagName, object caller)
        {
            ConfigBase cBase = ReadBase(tagName,staticReader);
            cBase.Caller = caller;
            cBase.AppendDelegate();
            return (List<MAPBase>)cBase.PullValue();
        }

        private static ConfigBase ReadBase(string tagName, IConfigReader reader)
        {
            return reader.ReadTag(tagName);
        }
    }
}